home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-10-05 | 6.4 KB | 276 lines | [TEXT/CWIE] |
- // © Paul B. Beeken, Work In Progress, 1994-5
- // Knowledge Software Consulting.
- //
- // These files are a mindlessly simple wrapper class for the
- // basic XCMD operations. Only one instance of the xcmdBase class is
- // generated per XCMD call but there may be many instances of the XCMDString
- // class. I have used these classes to whip out XCMD/XFCNs within hours of
- // receiving the specs. They work great for me but I will always consider
- // suggestions.
- //
- // Please, please, please, in the unlikely event you should use this stuff
- // for some commercial application I would appreciate you contacting me. If
- // its for your own use, use away. Send email: knowsoft@ios.com
- //
- // As always: this file is presented as is with no warrantees expressed or implied.
- // Swim at your own risk, etc. etc.
-
- #include "xcmdWind.h"
-
- xcmdWindow::xcmdWindow( XCmdPtr xP, Boolean lockParameters ) :
- xcmdBase( xP, lockParameters ) // set up xcmdBase and continue...
- {
-
- if ( nParams() < 0 ) { // This entry involves an "event"
-
- xEventInfo = XWEventInfoPtr( (*this)[0] ); // Get ext param block
- xEvent = xEventInfo->event; // Copy eventRecord
- xPrivStore = (Handle)GetWRefCon( (WindowPtr)getXWindow() );
- xWindow = (CWindowPtr)xEventInfo->eventWindow; // We are always color
-
- GetPort( &oldXPort ); // keep old port and...
- SetPort( (WindowPtr)xWindow ); // Setup new one.
-
- passMsg( true ); // the buck doesn't stop here
-
- }
-
- else { // plain jane call.
-
- xEventInfo = nil;
- xPrivStore = nil;
- oldXPort = nil;
- xWindow = nil;
- }
-
- }
-
- xcmdWindow::~xcmdWindow( void )
- {
- if ( isWindowEvent() ) { // We were called through an "event"
- SetWRefCon( (WindowPtr)getXWindow(), (long)xPrivStore ); // We may have changed the handle.
- SetPort( oldXPort ); // restore old environment
- } // if
- }
-
- CWindowPtr
- xcmdWindow::createWindow( short rID, ResType rType, Boolean floating )
- {
- // get from a template. (always a color window)
- return (CWindowPtr)
- GetNewXWindow( theParamPtr(), rType, rID, true, floating );
- }
-
- void
- xcmdWindow::doWindowEvent( void )
- {
- if ( !isWindowEvent() ) return;
-
- switch( xEvent.what ) {
- case xOpenEvt: /* the first event after you are created */
- doOpenWindow();
- break;
- case xCloseEvt: /* your window is being forced close (Quit?) */
- doCloseWindow();
- break;
-
- // We only get these calls if we made some special call to a call back.
- case xGiveUpEditEvt: /* you are losing Edit... */
- case xEditUndo: /* Edit——Undo */
- case xEditCut: /* Edit——Cut */
- case xEditCopy: /* Edit——Copy */
- case xEditPaste: /* Edit——Paste */
- case xEditClear: /* Edit——Clear */
- doEditEvent( xEvent.what );
- break;
-
- //case xGiveUpSoundEvt: /* you are losing the sound channel... */
- // homey don't play this.
-
- case xMBarClickedEvt: /* a menu is about to be shown--update if needed */
- doMenuUpdate();
- break;
- case xMenuEvt: /* user has selected an item in your menu */
- doMenuClick( long( getXEventParam(1) ), long( getXEventParam(2) ) );
- break;
-
- // These are not documented well.
- case xHidePalettesEvt: /* someone called HideHCPalettes */
- case xShowPalettesEvt: /* someone called ShowHCPalettes */
- ShowHide( (WindowPtr)getXWindow(), (xEvent.what==xShowPalettesEvt));
- passMsg( false );
- break;
-
- case xSendEvt: /* script has sent you a message (text) */
- doMessage( StringPtr( getXEventParam(0) ) );
- break;
-
- case xSetPropEvt: /* set a window property */
- doSetProperty( StringPtr( getXEventParam(0) ), StringPtr( getXEventParam(1) ) );
- break;
- case xGetPropEvt: /* get a window property */
- xcmdString* rs = doGetProperty( StringPtr( getXEventParam(0) ) );
- setXEventResult( rs );
- if ( rs ) delete rs;
- break;
-
- case xCursorWithin: /* cursor is within the window */
- doSetCursor();
- break;
-
- // The standard toolbox events
- case nullEvent: /* only gets called if we have "interupt" code */
- //doIdleStuff();
- break;
-
- case activateEvt: /* window is bcoming active */
- doAcitveWindow( xEvent.modifiers & activeFlag );
- break;
-
- case updateEvt:
- doUpdateWindow();
- passMsg( false );
- break;
-
- case app4Evt: /* suspend/resume */
- ShowHide( (WindowPtr)getXWindow(), (xEvent.message % 2 != 0));
- passMsg( false );
- break;
- } // switch
- }
-
- void
- xcmdWindow::doAcitveWindow( Boolean activating )
- {
- // an activate/deactivate event.
-
- if ( activating ) {
- ; // do some activating
- } else {
- ; // do some deactivating
- }
-
- }
-
- void
- xcmdWindow::doUpdateWindow( void )
- {
- ::BeginUpdate((WindowPtr)getXWindow());
-
- doDrawWindow();
-
- ::EndUpdate((WindowPtr)getXWindow());
- }
-
- // These are the default actions for the window. most do nothing.
- void
- xcmdWindow::doOpenWindow( void )
- {
- // Window is openning, initialize
-
- // Show it.
- ShowHide( (WindowPtr)getXWindow(), true );
-
- }
-
- void
- xcmdWindow::doCloseWindow( void )
- {
- // Window is closing, clean up
- passMsg( true ); // go ahead, close it.
- }
-
- void
- xcmdWindow::doEditEvent( short what )
- {
- // Handle events relating to editing.
- switch( what ) {
- case xGiveUpEditEvt: /* you are losing Edit... */
- case xEditUndo: /* Edit——Undo */
- case xEditCut: /* Edit——Cut */
- case xEditCopy: /* Edit——Copy */
- case xEditPaste: /* Edit——Paste */
- case xEditClear: /* Edit——Clear */
- ;
- }
- }
-
-
- void
- xcmdWindow::doMenuUpdate( void )
- {
- // A menuBar click, set up menus
- }
-
- void
- xcmdWindow::doMenuClick( long m, long i )
- {
- // A menu click
- }
-
-
- void
- xcmdWindow::doMessage( const xcmdString& msg )
- {
- // a send message to window...
- }
-
- void
- xcmdWindow::doDrawWindow( void )
- {
- // do some drawing.
- }
-
- void
- xcmdWindow::doSetProperty( const xcmdString& prop, const xcmdString& val )
- {
- // set a window property
- passMsg( true ); // let hypercard handle it
- }
-
- xcmdString*
- xcmdWindow::doGetProperty( const xcmdString& prop )
- {
- // get a window property
- passMsg( true ); // let hypercard handle it
- return nil;
- }
-
- void
- xcmdWindow::doSetCursor( void )
- {
- // cursor is within the window */
- passMsg( false ); // let hypercard handle it
- }
-
- // Accessors
-
- // These functions must be used with great care.
- // I don't check to see if the xEvent pointer is valid.
- CWindowPtr
- xcmdWindow::getXWindow( void )
- {
- return xWindow;
- }
-
- void*
- xcmdWindow::getXEventParam( int i )
- {
- return (void*) xEventInfo->eventParams[i];
- }
-
- void
- xcmdWindow::setXEventResult( xcmdString* rv )
- {
- if ( rv )
- xEventInfo->eventResult = Handle(*rv);
- else
- xEventInfo->eventResult = nil; // nil
- }
-
- EventRecord*
- xcmdWindow::getXEvent( void )
- {
- return &xEvent;
- }
-